/*
 * commons is a based project implemented
 * Copyright (C) 2024 Jasmine
 */
package com.commons.core.domain.pojo;

import java.io.Serializable;

import com.commons.core.exception.GlobalResultInfoEnum;

import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "统一交互数据")
public class ResultBody<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Schema(description = "响应码", example = "200")
    private Integer code;
    @Schema(description = "响应消息", example = "操作成功")
    private String message;
    @Schema(description = "业务返回值", example = "userInfo{}")
    private T data;

    public ResultBody() {}

    public ResultBody(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultBody success() {
        return new ResultBody(GlobalResultInfoEnum.SUCCESS.getCode(), GlobalResultInfoEnum.SUCCESS.getMessage(), null);
    }

    public static <E> ResultBody success(E data) {
        return new ResultBody(GlobalResultInfoEnum.SUCCESS.getCode(), GlobalResultInfoEnum.SUCCESS.getMessage(), data);
    }

    public static <E> ResultBody success(String message, E data) {
        return new ResultBody(GlobalResultInfoEnum.SUCCESS.getCode(), message, data);
    }

    public static ResultBody success(int code, String message) {
        return new ResultBody(code, message, null);
    }

    public static <E> ResultBody success(int code, E data) {
        return new ResultBody(code, GlobalResultInfoEnum.SUCCESS.getMessage(), data);
    }

    public static <E> ResultBody<E> success(int code, String message, E data) {
        return new ResultBody(code, message, data);
    }

    public static ResultBody failed() {
        return new ResultBody(GlobalResultInfoEnum.FAILED.getCode(), GlobalResultInfoEnum.FAILED.getMessage(), null);
    }

    public static ResultBody failed(int code) {
        return new ResultBody(code, GlobalResultInfoEnum.FAILED.getMessage(), null);
    }

    public static ResultBody failed(String message) {
        return new ResultBody(GlobalResultInfoEnum.FAILED.getCode(), message, null);
    }

    public static ResultBody failed(int code, String message) {
        return new ResultBody(code, message, null);
    }

    public static <E> ResultBody<E> failed(int code, String message, E data) {
        return new ResultBody(code, message, data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
